package com.uetoken.cn.adapter;

import android.graphics.Color;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.uetoken.cn.R;
import com.uetoken.cn.bean.PaymentMethodBean;
import com.uetoken.cn.utils.GlideApp;
import com.uetoken.cn.utils.Save2DecimalUtils;

import java.util.List;

/**
 * @author 谢杨
 * @time 2018/7/27 14:21
 * @class 描述:
 */
public class PaymentMethodAdapter extends BaseQuickAdapter<PaymentMethodBean, BaseViewHolder> {
    public PaymentMethodAdapter(int layoutResId, @Nullable List<PaymentMethodBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PaymentMethodBean item) {
        String amount = item.getAmount();
        String balance = item.getBalance();
        String balanceformat = item.getBalanceformat();
        int pursetypeid = item.getPursetypeid();
        String text;
        ImageView arrow = helper.getView(R.id.iv_item_payment_method_arrow);
        TextView mTvInsufficientBalance = helper.getView(R.id.tv_item_payment_method_insufficient_balance);
        //消费金额大于余额
        if (Double.parseDouble(amount) > Double.parseDouble(balance)) {
            helper.setTextColor(R.id.tv_item_payment_method_type, Color.parseColor("#CCCCCC"));
            helper.setTextColor(R.id.tv_item_payment_method_balance, Color.parseColor("#CCCCCC"));
            helper.setTextColor(R.id.tv_item_payment_method_insufficient_balance, Color.parseColor("#CCCCCC"));
            arrow.setVisibility(View.INVISIBLE);
            mTvInsufficientBalance.setVisibility(View.VISIBLE);
        }
        balance = Save2DecimalUtils.getDecimalPrecision(balance,2);
        GlideApp.with(mContext).load(item.getIcon()).placeholder(R.drawable.ic_placeholder).into((ImageView) helper.getView(R.id.iv_item_payment_method_icon));
        helper.setText(R.id.tv_item_payment_method_type, item.getType());
        helper.setText(R.id.tv_item_payment_method_balance, String.format(mContext.getResources().getString(R.string.str_balance), balance));
    }
}

